<?php

/**
 * 焦点图图片管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: FocusImgService.class.php v1.0 2014-06-23 17:27:03 $
 */
namespace Admin\Service;
class FocusImgService extends CommonService{
    
    /**
     * 添加图片
     * @param type $data
     * @return type
     */
    public function add($data) {
        $M = $this->getD();
        if(false === ($imgs = $M->create($data))){
            return $this->errorResultReturn($M->getError());
        }
        
        if(false === $M->add($imgs)){
            return $this->errorResultReturn("系统繁忙");
        }
        return $this->resultReturn(TRUE);
    }
    
    public function update($data) {
        $M = $this->getD();
        if(false === ($imgs = $M->create($data))){
            return $this->errorResultReturn($M->getError());
        }
        
        if(false === $M->save($imgs)){
            return $this->errorResultReturn("系统繁忙");
        }
        return $this->resultReturn(TRUE);
    }
    
    /**
     * 根据焦点图ID获取图片
     * @param type $fid
     * @return type
     */
    public function getByFid($fid) {
        $where = array("fid" => $fid);
        return $this->getD()->relation(true)->where($where)->select();
    }
    
    /**
     * 根据ID获取图片详情
     * @param type $id
     * @return type
     */
    public function getById($id) {
        return $this->getM()->getById($id);
    }
    
    /**
     * 删除图片
     * @param int $id
     * @return boolean
     */
    public function delete($id) {
        $where = array("id" => intval($id));
        return $this->getM()->where($where)->delete();
    }
    /**
     * 删除图片
     * @param int $id
     * @return boolean
     */
    public function deleteByFid($fid) {
        $where = array("fid" => intval($fid));
        return $this->getM()->where($where)->delete();
    }
    protected function getModelName() {
        return "FocusImg";
    }
}
